package com.shop.front.controller.user;

import com.shop.common.enums.System.SysConfigConst;
import com.shop.common.enums.user.ExtractTypeEnum;
import com.shop.domain.user.UserBill;
import com.shop.domain.user.UserIntegralBill;
import com.shop.front.dao.user.UserDao;
import com.shop.front.request.user.*;
import com.shop.front.service.system.SystemService;
import com.shop.front.service.user.*;
import com.shop.front.shiro.UserTokenUtil;
import com.shop.front.vo.store.StoreCartVo;
import com.shop.front.vo.store.StoreOrderVo;
import com.shop.front.vo.user.*;
import com.shop.web.context.WebContext;
import com.shop.web.response.BaseResponse;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(description = "用户相关", position = -1)
@RestController
@RequestMapping(value = "/user", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private RealNameAuthService realNameAuthService;
    @Autowired
    private UserBillService userBillService;
    @Autowired
    private UserIntegtralBillService userIntegtralBillService;
    @Autowired
    private UserSignInService userSignInService;
    @Autowired
    private SnapRedPinkService snapRedPinkService;
    @Autowired
    private SystemService systemService;



    @ApiOperation(value = "提现申请")
    @ApiResponses(@ApiResponse(code = 10000, response = String.class, message = "content"))
    @RequestMapping("/extract")
    public BaseResponse extract(@RequestBody @Validated UserExtractReq userExtractReq) {
    /*    ExtractTypeEnum extractTypeEnum = ExtractTypeEnum.val(userExtractReq.getExtractType());
        if(null == extractTypeEnum) {
            return BaseResponse.fail("提现类型错误！");
        }*/

        Long userId = UserTokenUtil.getUser().getId();
        //return BaseResponse.fail("系统升级中，预计工作时间开放申请！");
        return userService.extract(userId, userExtractReq);
    }

    @ApiOperation(value = "提现申请记录")
    @ApiResponses(@ApiResponse(code = 10000, response = UserExtractVo.class, message = "content"))
    @RequestMapping("/pageExtract")
    public BaseResponse pageExtract(@RequestBody @ApiIgnore Map<String, String> map) {
        Long userId = UserTokenUtil.getUser().getId();
        return userService.pageExtract(userId);
    }

    @ApiOperation(value = "用户收益统计")
    @ApiResponses(@ApiResponse(code = 10000, response = UserIncomeStatisticVo.class, message = "content"))
    @RequestMapping("/incomeStatistic")
    public BaseResponse incomeStatistic(@RequestBody @ApiIgnore Map<String, String> map) {
        Long userId = UserTokenUtil.getUser().getId();
        return userService.incomeStatistic(userId);
    }

    @ApiOperation(value = "实名认证")
    @ApiResponses(@ApiResponse(code = 10000, response = String.class, message = "content"))
    @RequestMapping(value = "/realNameAuth")
    public BaseResponse realNameAuth(@RequestBody @Validated RealNameAuthReq realNameAuthReq) {
        Long userId = UserTokenUtil.getUser().getId();
        String ip = WebContext.getRequestIp();
        return realNameAuthService.auth(userId, ip, realNameAuthReq);
    }

    @ApiOperation(value = "用户中心首页")
    @ApiResponses(@ApiResponse(code = 10000, response = UserCenterVo.class, message = "content"))
    @RequestMapping(value = "/userCenter")
    public BaseResponse userCenter() {
        Long userId = UserTokenUtil.getUser().getId();
        return userService.userCenter(userId);
    }

    @ApiOperation(value = "用户信息修改")
    @ApiResponses(@ApiResponse(code = 10000, response = String.class, message = "content"))
    @RequestMapping(value = "/modifyUserInfo")
    public BaseResponse modifyUserInfo(@RequestBody @Validated ModifyUserInfoReq modifyUserInfoReq) {
        Long userId = UserTokenUtil.getUser().getId();
        return userService.modifyUserInfo(userId, modifyUserInfoReq);
    }

    @ApiOperation(value = "用户头像修改")
    @ApiResponses(@ApiResponse(code = 10000, response = String.class, message = "content"))
    @RequestMapping(value = "/modifyUsePhoto")
    public BaseResponse modifyUsePhoto(@RequestBody @Validated ModifyUsePhotoReq modifyUsePhotoReq) {
        Long userId = UserTokenUtil.getUser().getId();
        return userService.modifyUsePhoto(userId, modifyUsePhotoReq);
    }


   /* @ApiOperation(value = "推广人统计")
    @ApiResponses(@ApiResponse(code = 10000, response = String.class, message = "content"))
    @RequestMapping("/statPromoter")
    public BaseResponse statPromoter(@RequestBody @ApiIgnore Map<String, String> map) {
        Long userId = UserTokenUtil.getUser().getId();
        return userService.statPromoter(userId);
    }*/





    @ApiOperation(value = "用户余额流水")
    @ApiResponses(@ApiResponse(code = 10000, response = UserBill.class, message = "content"))
    @RequestMapping("/pageUserBill")
    public BaseResponse pageUserBill(@RequestBody @ApiIgnore Map<String, String> map) {
        Long userId = UserTokenUtil.getUser().getId();
        return userBillService.pageUserBill(userId);
    }


    @ApiOperation(value = "用户积分流水")
    @ApiResponses(@ApiResponse(code = 10000, response = UserIntegralBill.class, message = "content"))
    @RequestMapping("/pageIntegralBill")
    public BaseResponse pageIntegralBill(@RequestBody @ApiIgnore Map<String, String> map) {
        Long userId = UserTokenUtil.getUser().getId();
        return userIntegtralBillService.getIntegralBills(userId);
    }


    @ApiOperation(value = "用户签到")
    @ApiResponses(@ApiResponse(code = 10000, response = UserSignInVo.class, message = "content"))
    @RequestMapping("/userSignIn")
    public BaseResponse userSignIn(@RequestBody @ApiIgnore Map<String, String> map) {
        Long userId = UserTokenUtil.getUser().getId();
        return userSignInService.userSignIn(userId);
    }



    @ApiOperation(value = "用户签到查询")
    @ApiResponses(@ApiResponse(code = 10000, response = UserSignInVo.class, message = "content"))
    @RequestMapping("/queryUserSignIn")
    public BaseResponse queryUserSignIn(@RequestBody @ApiIgnore Map<String, String> map) {
        Long userId = UserTokenUtil.getUser().getId();
        return userSignInService.getUserSignIn(userId);
    }

/*    @ApiOperation(value = "用户看视频赠送积分")
    @ApiResponses(@ApiResponse(code = 10000, response = String.class, message = "content"))
    @ApiImplicitParams(@ApiImplicitParam(name="videosId", required = true, value = "广告id", paramType = "body"))
    @RequestMapping("/watchVideosSendIntegral")
    public BaseResponse watchVideosSendIntegral(@RequestBody @ApiIgnore Map<String, String> map) {
        Long userId = UserTokenUtil.getUser().getId();
        String videosId = map.get("videosId");
        return userSignInService.watchVideosSendIntegral(userId,videosId);
    }*/


    @ApiOperation(value = "用户红包流水表")
    @ApiResponses(@ApiResponse(code = 10000, response = UserBill.class, message = "content"))
    @RequestMapping("/pageUserSnapRedBill")
    public BaseResponse pageUserSnapRedBill(@RequestBody @ApiIgnore Map<String, String> map) {
        Long userId = UserTokenUtil.getUser().getId();
        return snapRedPinkService.pageUserBill(userId);
    }


    @ApiOperation(value = "收藏 取消收藏")
    @ApiResponses(@ApiResponse(code = 10000, response = String.class, message = "content"))
    @ApiImplicitParams({@ApiImplicitParam(name="sign", required = true, value = "产品id", paramType = "body"),
            @ApiImplicitParam(name="type", required = true, value = "0 收藏 1取消收藏", paramType = "body")})
    @RequestMapping("/updateCollect")
    public BaseResponse updateCollect(@RequestBody @Validated Map<String, String> map) {
        Long id = WebContext.getSignId();
        String type = map.get("type");
        if(StringUtils.isBlank(type)){
            return BaseResponse.fail("请选择收藏类型");
        }
        return userService.updateCollect(id,type);
    }

    @ApiOperation(value = "我的收藏列表")
    @ApiResponses(@ApiResponse(code = 10000, response = StoreCartVo.class, message = "content"))
    @RequestMapping("/collectPage")
    public BaseResponse collectPage(@RequestBody @ApiIgnore Map<String, String> map) {

        Long userId = UserTokenUtil.getUser().getId();

        return userService.collectPage(userId);
    }




    @ApiOperation(value = "商品反馈")
    @ApiResponses(@ApiResponse(code = 10000, response = String.class, message = "content"))
    @RequestMapping(value = "/productFeedback")
    public BaseResponse productFeedback(@RequestBody @Validated ProductFeedBackReq productFeedBackReq) {
        Long userId = UserTokenUtil.getUser().getId();
        return userService.productFeedback(userId, productFeedBackReq);
    }



    /**
     * 用户头像昵称信息查询
     */
    @ApiOperation(value = "用户修改手机号码")
    @ApiResponses(@ApiResponse(code = 10000, response = BaseResponse.class, message = "content"))
    @ApiImplicitParams({@ApiImplicitParam(name = "newMobile", required = true, value = "新手机号码", paramType = "body"),@ApiImplicitParam(name = "smsCode", required = true, value = "短信验证码", paramType = "body")})
    @RequestMapping("/modifyBindModile")
    public BaseResponse modifyBindModile(@RequestBody Map<String, String> map) {

        String smsCode = map.get("smsCode");
        if (StringUtils.isBlank(smsCode)) {
            return BaseResponse.fail("请输入短信验证码");
        }
        String newMobile = map.get("newMobile");
        if(StringUtils.isBlank(newMobile)){
            return BaseResponse.fail("绑定手机号码不能为空！");
        }
        // 获取用户基本信息
        return  userService.modifyBindModile(newMobile,smsCode);
    }


    @ApiOperation(value = "客服图片地址")
    @ApiResponses(@ApiResponse(code = 10000, response = BaseResponse.class, message = "content"))
    @RequestMapping("/getCustomerImg")
    public BaseResponse getCustomerImg() {
        return new BaseResponse(systemService.getSysConfig(SysConfigConst.SYSTEM_CUSTOMER_IMG));
    }


}
